# -*- coding: utf-8 -*-

"""
@project: 神经网络python实现
@author:Jing
@file:AverageDM.py
@ide:PyCharm
@time1:2018-08-05 20:49:03
@个人爱好：游戏
"""

import pandas as pd
import numpy as np
import tensorflow as tf

class AverageDM:
    def __init__(self, n,q,sequence_length,k,p):
        self.n = n
        self.q = q
        self.sequence_length = sequence_length
        self.k=k
        self.p=p
        self.df=self.__create_average_DM_sequences()
    def __create_pair_demand(self):
        proba = np.random.random()
        if proba < 0.8:
            pair_demand = np.random.normal(150, 20)
        else:
            pair_demand = np.random.normal(400, 20)
        return pair_demand

    def __sparse_DM_matrix(self,dm_matrix):
        return  dm_matrix

    def __create_average_DM_sequences(self):
        DM_sequences=np.zeros((1, self.n * self.n))
        for i in range(self.q):
            DM_matrix = np.zeros((1, self.n * self.n))
            for j in range(0, self.n * self.n):
                DM_matrix[0,j] = self.__create_pair_demand()
            datas = self.__sparse_DM_matrix( DM_matrix)
            if i==0:
                DM_sequences=datas
            else:
                DM_sequences =np.vstack((DM_sequences, datas))
        for x in range(self.q,self.sequence_length):
            previous_q_DM=DM_sequences[(x-self.q):x]
            target_DM= np.mean(previous_q_DM,axis=0)
            target_DM=target_DM.astype(np.float32)
            DM_sequences=np.vstack((DM_sequences, target_DM))
            DM_sequences=DM_sequences.astype(np.float32)
        return DM_sequences


    def average_DM_data_x(self):

        a=0
        xs=[]
        for i in range(len(self.df)-self.k):
            x = []
            for j in range(a,a+self.k):
                x.extend(self.df[j])
           # print(x)
            xs.append(x)
            a=a+1
        return  xs

    def average_DM_data_y(self):
        ys=[]
        for i in range(self.k,len(self.df)):
            ys.append(self.df[i])
        return  ys

#c=AverageDM(2,5,6,3,1)
#x=c.average_DM_data_x()
#y=c.average_DM_data_y()
#_x=np.array(x)
#_y=np.array(y)
#print(_x.shape)
#print(_x)
#print(_y.shape)
#print(_y)




